"""
Case Type   : 系统内部使用工具
Case Name   : 查看gs_probackup set-backup命令的摘要信息
Create At   : 2021/02/02
Owner       : opentestcase015
Description :
    1.执行命令显示gs_probackup set-backup命令的摘要信息
Expect      :
    1.显示gs_probackup set-backup命令的摘要信息成功
History     :
    modified by l1azzzy at 2024/12/5:优化提示信息，以及逻辑，适配7.0.0-RC1版本
"""

import unittest

from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

LOG = Logger()


class SystemInternalTools(unittest.TestCase):
    def setUp(self):
        LOG.info('-------------------this is setup--------------------')
        LOG.info('-Opengauss_Function_Tools_Gs_Probackup_Case0020开始执行-')
        self.constant = Constant()
        self.PrimaryNode = Node('PrimaryDbUser')
        self.except_msg = ['gs_probackup set-backup -B backup-path '
                           '--instance=instance_name -i backup-id',
                           '[--note=text] [--ttl=interval] '
                           '[--expire-time=time]',
                           '[--media-type=type] [--access-id=ak] '
                           '[--access-key=sk]',
                           '[--access-bucket=bucket] [--endpoint=endpoint] '
                           '[--region=region]',
                           '[--s3-status=s3|local]',
                           '',
                           '-B, --backup-path=backup-path    '
                           'location of the backup storage area',
                           '--instance=instance_name     '
                           'name of the instance',
                           '-i, --backup-id=backup-id        '
                           'backup id',
                           "--note=text                  "
                           "add note to backup; 'none' to remove note",
                           "(example: --note='backup before "
                           "app update to v13.1')",
                           '--ttl=interval               '
                           'pin backup for specified amount of time; 0 unpin',
                           "available units: 'ms', 's', 'min', 'h', 'd' "
                           "(default: s)",
                           '(example: --ttl=20d)',
                           '--expire-time=time           '
                           'pin backup until specified time stamp',
                           "(example: --expire-time="
                           "'2024-01-01 00:00:00+03')",
                           '',
                           '',
                           'S3 options:',
                           '--media-type=type            '
                           'media type for storing backups, including: s3 and disk',
                           '--access-id=ak               '
                           'access key id, used to identify the user',
                           '--access-key=sk              '
                           'secret access key, used to verify the user\'s identity',
                           '--access-bucket=bucket       '
                           'name of the bucket created on the object storage',
                           '--endpoint=endpoint          '
                           'accessing domain name which can be in the form of IP: port',
                           '--region=region              '
                           'geographical region, optional parameters',
                           '--s3-status                  '
                           'current backup set status']

    def test_system_internal_tools(self):
        LOG.info('step1 执行命令显示gs_probackup set-backup命令的摘要信息')
        help_cmd = f"source {macro.DB_ENV_PATH};" \
            f"gs_probackup set-backup --help;"
        LOG.info(help_cmd)
        help_msg = self.PrimaryNode.sh(help_cmd).result()
        LOG.info(help_msg)
        line_msg = help_msg.splitlines()
        LOG.info(line_msg)
        for line in line_msg:
            LOG.info(line)
            self.assertIn(line.strip(), self.except_msg)

    def tearDown(self):
        LOG.info('--------------this is tearDown--------------')
        # 无须清理环境
        LOG.info('-Opengauss_Function_Tools_Gs_Probackup_Case0020执行完成-')
